const { DataTypes } = require("sequelize");

const requelize = require("../db/sequelize");

const User = require("./user.model");

const LeaveMessage = requelize.define(
  "db_leave_message",
  {
    id: {
      type: DataTypes.UUID,
      defaultValue: DataTypes.UUIDV4,
      unique: true,
      primaryKey: true,
      comment: "ID",
    },
    user_id: {
      type: DataTypes.STRING(64),
      allowNull: true,
      comment: "用户ID",
    },
    content: {
      type: DataTypes.TEXT,
      allowNull: true,
      comment: "内容",
    },
    parent_id: {
      type: DataTypes.STRING(64),
      allowNull: true,
      comment: "回复的留言ID",
    },
    status: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: "状态(走字典)",
    },
    like: {
      type: DataTypes.INTEGER,
      allowNull: true,
      comment: "点赞数",
    },
  },
  {
    tableName: "db_leave_message",
    comment: "留言表",
  }
);
LeaveMessage.belongsTo(User, {
  foreignKey: "user_id",
  targetKey: "id",
  as: "userInfo",
});

// 注释掉的代码块：这里原本是一个同步数据库表结构的调用，使用时需要解除注释并谨慎操作，因为它会强制同步表结构，可能导致数据丢失
// LeaveMessage.sync({ force: true });

// 导出用户模型，供其他模块使用
module.exports = LeaveMessage;
